package com.mmy.fta.cargo.web.rest;

import com.mmy.fta.cargo.server.dto.*;
import com.mmy.fta.cargo.server.service.CarrierBlackboardPageService;
import com.mmy.fta.cargo.server.service.PublishCargoInfoService;
import com.mmy.fta.cargo.web.request.CarrierBlackboardRequest;
import com.mmy.fta.cargo.web.response.CargoBlackboardPageResponse;
import com.ymm.common.rpc.YmmResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author guohao.xie
 * @apiNote
 * @exportable
 * @since 2021/10/26
 */
@RestController
@RequestMapping(value = "/currentCargo")
@Slf4j
public class CarrierBlackboardController {
    @Autowired
    CarrierBlackboardPageService carrierBlackboardPageService;

    @Autowired
    PublishCargoInfoService publishCargoInfoService;

    /**
     * 司机端当天货源
     */
    @PostMapping(value = "carrierQueryCurrentCargo")
    public YmmResult<CargoBlackboardPageResponse> getCarrierCurrentCargo(@RequestBody CarrierBlackboardRequest carrierBlackboardRequest) {
        try {
            if (null == carrierBlackboardRequest) {
                return YmmResult.failResult(0, "请求参数为空");
            }
            CarrierBlackboardRequestDTO carrierBlackboardRequestDTO = new CarrierBlackboardRequestDTO();
            BeanUtils.copyProperties(carrierBlackboardRequest, carrierBlackboardRequestDTO);

            CarrierBlackboardPageDTO carrierBlackboardPageDTO = carrierBlackboardPageService.queryCargosByDriver(carrierBlackboardRequestDTO);
            CargoBlackboardPageResponse cargoBlackboardPageResponse = new CargoBlackboardPageResponse();

            BeanUtils.copyProperties(carrierBlackboardPageDTO, cargoBlackboardPageResponse);
            log.info("司机当天货源显示：{}",cargoBlackboardPageResponse);
            return YmmResult.succResult(cargoBlackboardPageResponse);
        } catch (Exception e) {
            return YmmResult.failResult(0, "调用失败");
        }
    }

}
